<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="dist/datatables/dataTables.bootstrap.css">
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<title>朗读亭——管理员管理</title>
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body>
	<section class="content-header">
      <h1>
        设备故障记录
        <small>设备故障历史记录查询</small>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">
     
      <div class="row">
        <div class="col-xs-12">

          <div class="box">
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>设备编号</th>
                  <th>故障信息</th>
                  <th>是否已解决</th>
                  <th>备注</th>
                  <th>故障时间</th>
                  <th>解决时间</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="info" items="${list }">
                <tr>
	                  <td>${info.devicecode }</td>
	                  <td>${info.fault }</td>
	                  <c:choose>
								   <c:when test="${0 == info.state}">
								   <td class="center"><span class="label label-danger">否</span></td>
								   </c:when>
								   <c:when test="${1 == info.state}">
								   <td class="center"><span class="label label-success">是</span></td>
								   </c:when>
								   
								    
								 </c:choose>
	                  <td>${info.info }</td>
	                 
	                  <td>${info.checkdate }</td>
	                  <td>${info.repairdate }</td>
					 
	                  <td>
	                  <c:if test = "${0 == info.state}">
	                  <a class="btn btn-warning" href="javascript:void(0);" onclick="repair(${info.reco});">已解决</a>
	                  </c:if>	                  
	                  <a class="btn btn-danger" href="javascript:void(0);"onclick="deleteItem(${info.reco})">删除</a>
	                  <a class="btn btn-info" href="javascript:void(0);" onclick="addinfo(${info.reco});">添加备注</a></td>
                </tr>
                </c:forEach>
                </tbody>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/bootstrap.js"></script>
<script src="dist/datatables/jquery.dataTables.min.js"></script>
<script src="dist/datatables/dataTables.bootstrap.min.js"></script>
<script src="dist/js/app.min.js"></script>
<script type="text/javascript" src="js/layer/layer.js"></script>
<script>
  $(function () {
    $("#example1").DataTable();
  });
  function deleteItem(id){
	  layer.confirm('你确定要删除吗?', {
 		  title:'删除',
 		  btn: ['确定','取消'] //按钮
 		}, function(){  
  			$.ajax({
				async : false,
				cache : false,
				type : 'post',
				dataType : "json",
				url : 'device/delete_faultlog?id='+id ,// 请求的action路径
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("请求失败！");
				},
				success : function(data) {
					if(data.state=="9003"){
						layer.msg("没有权限！");
						return ;
					}else if(data.state=="9002"){
						layer.msg("请重新登录！");
						top.location.reload();
						return ;
					}
					if(data){
						layer.msg("删除成功！");
						window.location.reload();
					}else{
						layer.msg("删除失败！");
					}
				}
			});	
  		}, function(){
  		}); 
  }
  function repair(id){
	  layer.confirm('确定要已经完成修复该故障了吗?', {
 		  title:'故障修复',
 		  btn: ['确定','取消'] //按钮
 		}, function(){  
  			$.ajax({
				async : false,
				cache : false,
				type : 'post',
				dataType : "json",
				url : 'device/repair_faultlog?id='+id ,// 请求的action路径
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("请求失败！");
				},
				success : function(data) {
					if(data.state=="9003"){
						layer.msg("没有权限！");
						return ;
					}else if(data.state=="9002"){
						layer.msg("请重新登录！");
						top.location.reload();
						return ;
					}
					if(data){
						layer.msg("更改成功！");
						window.location.reload();
					}else{
						layer.msg("更改失败！");
					}
				}
			});	
  		}, function(){
  		}); 
  }
  function addinfo(id){
	  layer.open({
		  title:'备注',
		  type: 2,
		  area: ['650px', '330px'],
		  fixed: false, //不固定
		  //maxmin: true,
		  content: 'device/info_faultlog?id='+id
		});
  }
  function regetlist(){
	  window.location.reload();
  }
</script>
</body>
</html>